home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / keyboard / wrapinp.asm < prev   
Encoding:
Assembly Source File  |  1989-05-03  |  7.4 KB  |  238 lines

  1. ;void wrap_input(row,left_col,right_col,color,max_len,return_string);
  2. ;  unsigned short  row,left_col,right_col,color,max_len;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.     EXTRN  _beep_on:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _wrap_input
  11. _wrap_input proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set up stack frame
  14.     push di            ;
  15.     push si            ;
  16.     mov  _error_code,1    ;1 = parameter out of range
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    cmp  _memory_model,2    ;data near or far?
  22.     jb   L0            ;jump if near
  23.     les  di,dword ptr[bp+14]  ;get ptr to return string
  24.     jmp  short L00        ;
  25. L0:    mov  ax,ds        ;ES = DS
  26.     mov  es,ax        ;
  27.     mov  di,[bp+14]        ;
  28. L00:    sub  al,al        ;clear AL
  29.     mov  es:[di],al        ;return null if error
  30.     mov  ah,[bp+12]        ;AH=maximum string len
  31.     or   ah,ah        ;test if AH=0
  32.     jnz  B1            ;jump ahead if not
  33. A1:    jmp  Z1            ;quit routine if null str
  34. B1:    sub  al,al        ;AL=initial string len
  35.     mov  si,ax        ;store 2 values in SI
  36.     sub  bh,bh        ;page 0
  37.     mov  bl,[bp+10]        ;attribute byte in BL
  38.     mov  cl,[bp+8]        ;right column in CL
  39.     mov  ch,[bp+6]        ;left column in CH
  40.     cmp  cl,ch        ;compare the two cols
  41.     jna  A1            ;quit if right not > left
  42.     dec  cl            ;count right col from 0
  43.     cmp  cl,79        ;in range?
  44.     ja   A1            ;quit if not
  45.     dec  ch            ;count left col from 0
  46.     cmp  ch,79        ;in range?
  47.     ja   A1            ;quit if not
  48.     mov  ah,[bp+4]        ;starting row in AH
  49.     dec  ah            ;count rows from 0
  50.     cmp  ah,24        ;in range?
  51.     ja   A1            ;quit if not
  52.     dec  _error_code    ;0 = no error
  53.     mov  al,0FFH        ;flg last spc chr,FF=none
  54.     mov  bp,di        ;let BP point to return strg
  55.     mov  di,ax        ;store 'lastspc' in DI
  56.     mov  dh,ah        ;current cursor row in DH
  57.     mov  dl,ch        ;current cursor col in DL
  58.     mov  ah,2        ;function to set cursor
  59.     int  10h        ;set initial cursor
  60. C1:    sub  ah,ah        ;func to read keystroke
  61.     int  16h        ;wait for a keystroke
  62.     or   al,al        ;extended code?
  63.     jnz  D1            ;jump ahead if not
  64.     int  16h        ;clear 2nd byte of code
  65.     jmp  short C1        ;go get next keystroke
  66. D1:    cmp  al,8        ;is it the backspace?
  67.     jne  E1            ;jump ahead if not
  68.     jmp  Q1            ;jump to bkspc routine
  69. E1:    cmp  al,13        ;is it a carriage return?
  70.     jne  F1            ;jump ahead if not
  71.     jmp  Z1            ;go quit the routine
  72. F1:    cmp  al,27        ;is it escape?
  73.     jne  G1            ;jump ahead if not
  74.     sub  al,al        ;ready to set null string
  75.     mov  es:[bp],al        ;set return str to null
  76.     jmp  Z1            ;go quit the routine
  77. G1:    cmp  al,32        ;an other char < 32?
  78.     jb   C1            ;reject it if so
  79.     xchg ax,si        ;get string length ctr
  80.     cmp  al,ah        ;equal to maxlen?
  81.     jne  I1            ;jump ahead if not
  82.     xchg ax,si        ;return ctr to SI
  83. H1:    push dx            ;get ready to beep
  84.     mov  ah,2        ;DOS screen write func
  85.     mov  dl,7        ;bell character
  86.     cmp  _beep_on,0        ;see if beep is enabled
  87.     jz   H2            ;jump ahead if not
  88.     int  21h        ;beep!
  89. H2:    pop  dx            ;restore DX
  90.     jmp  short C1        ;go wait for next char
  91. I1:    inc  al            ;increment counter
  92.     xchg ax,si        ;send back to SI
  93.     cmp  al,32        ;test for spc char
  94.     jne  J1            ;jump if not spc char
  95.     xchg ax,di        ;swap 'lastspc' to AL
  96.     mov  al,dl        ;current col to AL
  97.     xchg ax,di        ;swap back to DI
  98. J1:    push cx            ;save CX contents
  99.     push si            ;SI changed below
  100.     mov  ah,1        ;increment for str length
  101.     add  es:[bp],ah        ;increment the length
  102.     sub  cx,cx        ;clear CX
  103.     mov  cl,es:[bp]        ;str len to CX
  104.     mov  si,cx        ;move to SI
  105.     mov  es:[bp][si],al    ;set the character
  106.     pop  si            ;restore SI
  107.     mov  cx,1        ;number chars to write
  108.     mov  ah,9        ;function to write char
  109.     int  10h        ;write the char
  110.     pop  cx            ;restore CX
  111.     cmp  cl,dl        ;end of line position?
  112.     jne  O1            ;jump ahead if not
  113.     cmp  al,32        ;is end of line a spc?
  114.     je   N1            ;no wrap, go print it
  115.     mov  ax,di        ;get 'prior spc' ptr
  116.     cmp  al,0ffh        ;test for any spaces
  117.     jne  K1            ;jump ahead if found
  118.     jmp  N1            ;else don't wrap
  119. K1:    push di            ;DI changed
  120.     mov  ah,dh        ;save row in AH
  121.     inc  dh            ;point to next row
  122.     mov  dl,ch        ;point to left col
  123.     xchg dx,di        ;now DL=col of prior spc
  124.     mov  dh,ah        ;current row to DH
  125.     inc  dl            ;prior spc col + 1
  126. L1:    mov  ah,2        ;func to set cursor
  127.     int  10h        ;set the cursor
  128.     mov  ah,8        ;func reads char at curs
  129.     int  10h        ;char to AL
  130.     push cx            ;save left/right col vals
  131.     push ax            ;save keystroke in AL
  132.     mov  al,0FFH        ;erase eol with FF char
  133.     mov  ah,9        ;function to write char
  134.     mov  cx,1        ;number chars to write
  135.     int  10h        ;erase end-of-line char
  136.     xchg dx,di        ;cursor pos below to DX
  137.     mov  ah,2        ;function to set cursor
  138.     int  10h        ;set cursor to below
  139.     pop  ax            ;restore char to AL
  140.     mov  ah,9        ;function to write char
  141.     mov  cx,1        ;number chars to write
  142.     int  10h        ;write the char in AL
  143.     pop  cx            ;restore CX
  144.     inc  dl            ;set col position forward
  145.     xchg dx,di        ;return cursor pos above
  146.     cmp  dl,cl        ;end of line?
  147.     je   M1            ;jump ahead if so
  148.     inc  dl            ;col plus one
  149.     jmp  short L1        ;go transfer next char
  150. M1:    xchg dx,di        ;return cursor pos below
  151.     mov  ah,2        ;function to set cursor
  152.     int  10h        ;set the cursor
  153.     pop  ax            ;restore DI to AX
  154.     mov  al,0ffh        ;reset 'prior spc' ptr
  155.     mov  di,ax        ;now place in DI
  156.     jmp  C1            ;go get next char
  157. N1:    inc  dh            ;cursor to next row
  158.     mov  dl,ch        ;cursor to left col
  159.     mov  ax,di        ;get 'prior spc' ptr
  160.     mov  al,0ffh        ;reset to FF
  161.     mov  di,ax        ;return it to DI
  162.     jmp  short P1        ;jump ahead
  163. O1:    inc  dl            ;cursor to next col
  164. P1:    mov  ah,2        ;function to set cursor
  165.     int  10h        ;set the cursor
  166.     jmp  C1            ;go get next keystroke
  167. Q1:    cmp  dl,ch        ;BACKSPACE: left col?
  168.     jne  X1            ;jump ahead if not
  169.     mov  ax,di        ;now AH has start row
  170.     cmp  dh,ah        ;same as current row?
  171.     jne  R1            ;jump ahead if not
  172.     jmp  H1            ;else go beep
  173. R1:    dec  dh            ;dec row ptr
  174.     mov  dl,cl        ;left col position
  175. S1:    mov  ah,2        ;func to set cursor
  176.     int  10h        ;set the cursor
  177.     mov  ah,8        ;func to read char
  178.     int  10h        ;read char at cursor
  179.     cmp  al,0FFH        ;is it a fill char?
  180.     jne  T1            ;jump ahead if not
  181.     dec  dl            ;dec col position
  182.     jmp  short S1        ;chk next char to left
  183. T1:    push dx            ;seek "last space" pos
  184. U1:    dec  dl            ;dec cursor col
  185.     cmp  dl,ch        ;left margin?
  186.     jnb  V1            ;jump ahead if not
  187.     mov  ah,0ffh        ;else no space on line
  188.     jmp  short W1        ;jump ahead
  189. V1:    mov  ah,2        ;function to set cursor
  190.     int  10h        ;set the cursor
  191.     mov  ah,8        ;function to fetch char
  192.     int  10h        ;get char at position
  193.     cmp  al,32        ;is it a space?
  194.     jne  U1            ;loop if not
  195.     mov  ah,dl        ;else save pos in AH
  196. W1:    mov  dx,di        ;"last space" in DI (low)
  197.     mov  dl,ah        ;set new "last space"
  198.     mov  di,dx        ;replace in DI
  199.     pop  dx            ;restore current curs pos
  200.     mov  ah,2        ;func to set cursor
  201.     int  10h        ;reset current cursor
  202.     jmp  short Y1        ;jump, continue backspc
  203. X1:    dec  dl            ;decrement col ptr
  204.     mov  ah,2        ;function to set cursor
  205.     int  10h        ;set the cursor
  206.     jmp  short T1        ;reset "last space"
  207. Y1:    mov  al,' '        ;use spc char to erase
  208.     mov  ah,9        ;function to write char
  209.     push cx            ;must change CX
  210.     mov  cx,1        ;number chars to write
  211.     int  10h        ;write the space char
  212.     pop  cx            ;restore CX
  213.     mov  ah,es:[bp]        ;get ret str descriptor
  214.     dec  ah            ;decrement it
  215.     mov  es:[bp],ah        ;replace
  216.     xchg si,ax        ;get string len ctr
  217.     dec  al            ;decrement it
  218.     xchg si,ax        ;replace
  219.     jmp  C1            ;go get next keystroke
  220. Z1:    sub  cx,cx        ;change to C string
  221.     mov  cl,es:[bp]        ;get string length
  222.     jcxz B2            ;quit if null
  223. A2:    inc  bp            ;
  224.     mov  al,es:[bp]        ;
  225.     mov  es:[bp-1],al    ;
  226.     loop A2            ;
  227.     mov  byte ptr es:[bp],0    ;null terminator
  228. B2:    pop  si            ;
  229.     pop  di            ;
  230.     pop  bp            ;
  231.     cmp  _memory_model,0    ;quit
  232.     jle  quit        ;
  233.     db   0CBh        ;RET far
  234. quit:    ret            ;RET near
  235. _wrap_input ENDP
  236. _TEXT    ENDS
  237.     END
  238.